;*************************************************************************
; Title:	DriveName
; Author:	Original by Unknown
;		Converted to ObjAsm source code by Philip Ludlam
; Copyright:	(C) Philip Ludlam 2006
; Version:	1.01, 7 May 2006
;
; Changes:	Updated for the A9home by Philip Ludlam
;
;*************************************************************************
; This program is free software; you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by the Free
; Software Foundation; either version 2 of the License, or (at your option)
; any later version.
;
; This program is distributed in the hope that it will be useful, but WITHOUT
; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
; FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more
; details.
;
; You should have received a copy of the GNU General Public License along with
; this program; if not, write to the Free Software Foundation, Inc., 59 Temple
; Place - Suite 330, Boston, MA 02111-1307, USA
;
;*************************************************************************


		TTL	> DriveName

		GET	OSLib:oslib.hdr.OS
		GET	OSLib:oslib.hdr.OSFSControl
		GET	AsmLib2:hdr.RegsBoth

		AREA	|main|, CODE, READONLY

		ENTRY

;-------------------------------------------------------------------------------

Start		B	Entry			; Entry instruction
		DCD	&79766748		; Magic value 1
		DCD	&216C6776		; Magic value 2
		DCD	End-Start		; Read only size
		DCD	0			; Read/write size
		DCD	32			; 26 or 32 bit build

Entry		ADR	r0, args
		MOV	r2, r12
		MOV	r3, #256
		SWI	XOS_ReadArgs
		ADRVS   r0, syntax_error
		MOVVS	pc, lr					; exit if error

		MOV	r0, #OSFSControl_CanonicalisePath	; r0 = 37
		LDR	r1, [r12, #4]				; pointer to 'ADFS::4'
		ADD	r2, r12, #256
		MOV	r5, #256
		SWI	XOS_FSControl
		MOVVS	pc, lr					; exit if error

		MOV	r1, r2
find_name
		LDRB	r0, [r1], #1
		CMP	r0, #0
		BEQ	exit
		CMP	r0, #":"
		BNE	find_name

		LDRB	r0, [r1], #1
		CMP	r0, #0
		BEQ	exit
		CMP	r0, #":"
		BNE	find_name

		MOV	r3, r1
find_end
		LDRB	r0, [r3], #1
		CMP	r0, #0
		CMPNE	r0, #"."
		BNE	find_end
		MOV	r0, #0
		STRB	r0, [r3, #-1]

		SUB	r2, r3, r1
setvar
		LDR	r0, [r12, #0]
		MOV	r3, #0
		MOV	r4, #OS_VartypeString	; r4 = 0
		SWI	XOS_SetVarVal

exit
		MOV	pc, lr


syntax_error
		DCD	17
		DCB	"Syntax: *DriveName <varname> <drivespec>"
		DCB	0
		ALIGN
args
		DCB	"/a,/a"
		DCB	0

licence		DCB	" PJL, 2002. Licence: GPL."
		ALIGN

End
		END
